<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    //需求：为Array添加：1）删除指定下标的元素  2）删除指定内容的元素
    console.dir(Array);
    //1）删除指定下标的元素
    Array.prototype.removeAt = function (n) {
      if (!isNaN(n) && n < this.length) {
        this.splice(n, 1); //this代表当前实例化的数组
      } else {
        return;
      }
    };

    console.dir(Array);
    var arr = [1, 2, 3, 4, 5];
    console.log(arr);
    arr.removeAt(1);
    console.log(arr);

    // 2）删除指定内容的元素
    Array.prototype.remove = function (parms) {
      if (typeof parms !== "object") {
        for (var i = 0; i < this.length; i++) {
          //this代表当前实例化的数组
          if (this[i] == parms) {
            this.splice(i, 1);
            i--;
          }
        }
      }
    };
    var arr1 = [1, 2, 3, 4, 5, 3, "abc"];
    console.log(arr1);
    arr1.remove(3);
    arr1.remove("abc");
    console.log(arr1);
  </script>
</html>
